//package com.example.sse.demos.web;
//
//import org.springframework.http.MediaType;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
//
//import java.io.IOException;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//
//@RestController
//public class SSEController {
//
//    private final ExecutorService executorService = Executors.newSingleThreadExecutor();
//
//    @GetMapping(path = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
//    public SseEmitter sseEmitter() {
//        SseEmitter sseEmitter = new SseEmitter(Long.MAX_VALUE);
//
//        executorService.execute(() -> {
//            try {
//                for (int i = 0; i < 10; i++) {
//                    sseEmitter.send(SseEmitter.event()
//                            .name("message")
//                            .data("Hello, this is message " + i)
//                            .reconnectTime(3000));
//                    Thread.sleep(1000);
//                }
//                sseEmitter.complete();
//            } catch (IOException | InterruptedException e) {
//                sseEmitter.completeWithError(e);
//            }
//        });
//
//        return sseEmitter;
//    }
//}
